/*
 * main.c
 *
 *  Created on: 2022年12月7日
 *      Author: hello
 */


#include "textcodec.h"
#include <string.h>
#include <stdio.h>

int main()
{
	const char* text = "你好ABC世界";            /* 注意：当前文件的编码格式为UTF-8 */
	uint32_t utf8Size, unicodeSize, gbkSize;
	uint8_t utf8[64];
	uint8_t unicode[64];
	uint8_t gbk[64];

	//
	// 打印原始数据：本文件是UTF-8编码的
	//
	printf(" ------ byte array in UTF8 format: ");
	for(int i = 0; i < strlen(text); i++)
	{
		printf("0x%02X,", text[i] & 0XFF);
	}
	printf("\n");

	//
	// UTF8转UNICODE
	//
	printf(" ------ utf8 to unicode : ");
	UTF8ToUnicode((const uint8_t *)text, strlen(text), unicode, &unicodeSize);
	for(int i = 0; i < unicodeSize; i++)
	{
		printf("0x%02X,", unicode[i] & 0XFF);
	}
	printf("\n");

	//
	// UTF8转GBK
	//
	UTF8ToGBK((const uint8_t *)text, strlen(text), gbk, &gbkSize);
	printf(" ------ utf8 to gbk     : ");
	for(int i = 0; i < gbkSize; i++)
	{
		printf("0x%02X,", gbk[i] & 0XFF);
	}
	printf("\n");

	//
	// GBK转UNICODE
	//
	printf(" ------ gbk  to unicode : ");
	GBKToUnicode((const uint8_t *)gbk, gbkSize, unicode, &unicodeSize);
	for(int i = 0; i < unicodeSize; i++)
	{
		printf("0x%02X,", unicode[i] & 0XFF);
	}
	printf("\n");

	//
	// GBK转UTF8
	//
	GBKToUTF8(gbk, gbkSize, utf8, &utf8Size);
	printf(" ------ gbk  to utf8    : ");
	for(int i = 0; i < utf8Size; i++)
	{
		printf("0x%02X,", utf8[i] & 0XFF);
	}
	printf("\n");

	//
	// UNICODE转UTF8
	//
	UnicodeToUTF8(unicode, unicodeSize, utf8, &utf8Size);
	printf(" ------ unicode to utf8 : ");
	for(int i = 0; i < utf8Size; i++)
	{
		printf("0x%02X,", utf8[i] & 0XFF);
	}
	printf("\n");

	//
	// unicode转gbk
	//
	UnicodeToGBK(unicode, unicodeSize, gbk, &gbkSize);
	printf(" ------ unicode to gbk  : ");
	for(int i = 0; i < gbkSize; i++)
	{
		printf("0x%02X,", gbk[i] & 0XFF);
	}
	printf("\n");

	//
	// HEX转STR
	//
	uint8_t hex[3] = {0XAA, 0XBB, 0XCC};
	uint32_t hexSize;
	char     str[32];
	uint32_t strSize;
	HexToStr(hex, 3, str, &strSize);
	printf(" ------ HEX TO STR: %s \n", str);

	//
	// STR转HEX
	//
	StrToHex(str, strSize, hex, &hexSize);
	printf(" ------ STR TO HEX: 0x%02X,0x%02X,0x%02X \n", hex[0], hex[1], hex[2]);

	return 0;
}
